package com.ant.storage.controller;

import com.ant.storage.common.ResultCode;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.CnxjrjzDto;
import com.ant.storage.handler.AntException;
import com.ant.storage.pojo.Cnxjrjz;
import com.ant.storage.service.ICnxjrjzService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author  hzd
 * @date  2024/7/9 10:37
 * @version 1.0
 */

@RestController
@RequestMapping("/Cnxjrjz")
@Api(tags = "现金日记账接口")
public class CnxjrjzController {

    @Autowired
    private ICnxjrjzService cnxjrjzService;

    @ApiOperation(value = "获取列表")
    @GetMapping("/list")
    public ResultVo list(CnxjrjzDto dto) throws Exception {
        return ResultVo.success("操作成功",cnxjrjzService.getList(dto));
    }

    @ApiOperation(value = "保存")
    @PostMapping("/saveCnxjrjz")
    public ResultVo saveCnxjrjz(@RequestBody Cnxjrjz cnxjrjz) throws Exception {
        cnxjrjzService.saveCnxjrjz(cnxjrjz);
        return ResultVo.success("操作成功");
    }

    @ApiOperation(value = "通过id获取详情")
    @GetMapping("/getById/{id}")
    public ResultVo getById(@PathVariable("id") Long id){
        Cnxjrjz detail = cnxjrjzService.getOne(new QueryWrapper<Cnxjrjz>().eq("FID",id));
        return ResultVo.success("操作成功",detail);
    }

    @ApiOperation(value = "通过id获取详情")
    @GetMapping("/getUrbanRevenue/{id}")
    public ResultVo getUrbanRevenue(@PathVariable("id") Integer id) throws Exception {
        if(id==0){
            throw new AntException(ResultCode.FAILURE.getCode(),"参数不能为空");
        }
        return ResultVo.success("操作成功",cnxjrjzService.getUrbanRevenue(id));
    }
}
